package cn.tedu.cwfw.pet.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.pet.pojo.dto.PetCateSaveParam;
import cn.tedu.cwfw.pet.pojo.vo.PetCategoryVO;
import cn.tedu.cwfw.pet.service.PetCateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cwfw/petCategory")
@Slf4j
public class PetCateController {
    @Autowired
    PetCateService petCateService;

//    添加宠物分类
    @PostMapping("/insert")
    public JsonResult insert(PetCateSaveParam petCateSaveParam){
        log.debug("添加宠物分类:{}",petCateSaveParam);

        petCateService.insert(petCateSaveParam);
        return JsonResult.ok();
    }
//    查看所有宠物分类
    @GetMapping("/findAll")
    public JsonResult findAll(){
        log.debug("查看所有宠物分类");
        List<PetCategoryVO> petCategoryVOS = petCateService.findAll();
        return JsonResult.ok(petCategoryVOS);
    }
//    根据宠物类型查看所有对应宠物
    @GetMapping("/findByType/{petType}")
    public JsonResult findByType(Long petType){
        log.debug("根据宠物类型查看所有对应宠物:{}",petType);
        List<PetCategoryVO> petCategoryVOS = petCateService.findByType(petType);
        return JsonResult.ok(petCategoryVOS);
    }
//    删除宠物类型
    @PostMapping("/delete/{id}")
    public JsonResult delete(Long id){
        log.debug("删除宠物类型:{}",id);
        petCateService.delete(id);
        return JsonResult.ok();
    }
//    修改宠物类型
    @PostMapping("/update")
    public JsonResult update(PetCateSaveParam petCateSaveParam){
        log.debug("修改宠物类型:{}",petCateSaveParam);
        petCateService.update(petCateSaveParam);
        return JsonResult.ok();
    }

}
